from typing import TypeVar

from .metric import Metric

AnyValue = TypeVar("AnyValue")


class ValueMetric(Metric[AnyValue | None, AnyValue]):
    def __init__(self, initial: AnyValue | None = None):
        self._value = initial

    def update(self, patch: AnyValue):
        self._value = patch

    def compute(self) -> AnyValue | None:
        return self._value

    def reset(self):
        self._value = None
